package com.atguigu.orderservice.controller;


import com.atguigu.commonutils.ClientEntity.ClientCourse;
import com.atguigu.commonutils.ClientEntity.ClientMember;
import com.atguigu.commonutils.JwtUtils;
import com.atguigu.commonutils.R;
import com.atguigu.orderservice.client.CourseClient;
import com.atguigu.orderservice.client.UserClient;
import com.atguigu.orderservice.service.TOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author huangqicai
 * @since 2023-03-31
 */
@Api(value = "课程下单模块接口")
@RestController
@RequestMapping("/orderservice")
//原来需要在Controller上面加上@CrossOrigin解决跨域问题，现在gateway已经处理了/*解决跨域问题*/
public class TOrderController {

    @Autowired
    private TOrderService orderService;

    @ApiOperation(value = "根据课程id创建订单没有支付，涉及到两个远程调用")
    @PostMapping("/saveOrder/{courseId}")
    public R saveOrder(@PathVariable(value = "courseId") String courseId,HttpServletRequest request){
        return orderService.saveOrder(courseId,request);
    }



    @ApiOperation(value = "根据订单id获取订单信息")
    @GetMapping("/getOrderInfo/{orderNoId}")
    public R getOrderInfo(@PathVariable(value = "orderNoId") String orderNoId){
        System.out.println("");
        return orderService.getOrderInfo(orderNoId);
    }


    @ApiOperation(value = "根据用户id和课程id查询订单信息,被远程调用的")
    @GetMapping(value = "/isBuyCourse/{memberId}/{courseId}")
    public boolean isBuyCourse(@PathVariable(value = "memberId") String memberId,
                         @PathVariable(value = "courseId") String courseId){
        return orderService.isBuyCourse(memberId,courseId);
    }



}

